﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataProvider
{
    public class XL_Bang
    {
        public SqlConnection connect = new SqlConnection();
        public SqlCommand command; // = new SqlCommand();
        #region Cac thuoc tinh
        private string _strSQL;

        public string StrSQL
        {
            get { return _strSQL; }
            set { _strSQL = value; }
        }
        #endregion

        #region Cac phuong thuc
        public XL_Bang()
        {
            

        }

        public DataTable GetDataTable()
        {
            try
            {
                open();
                SqlDataAdapter adapter = new SqlDataAdapter(_strSQL, connect);
                DataTable table = new DataTable();
                adapter.Fill(table);
                
                return table;
            }
            catch (Exception)
            {
                return null;

            }
            finally
            {
                close();
            }
        }

        public void open()
        {
            if (connect.State == ConnectionState.Closed)
                connect.Open();
        }
        public void close()
        {
            if (connect.State == ConnectionState.Open)
                connect.Close();
        }
        #endregion
    }
}
